#include <FreeRTOS_AVR.h>
int led = 13;
int sw = 12;
SemaphoreHandle_t sem;
static void a(void *arg) {
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
  while (1) {
    xSemaphoreTake(sem, portMAX_DELAY);
    digitalWrite(led, !digitalRead(led));
    while(digitalRead(sw)==LOW);
  }
}
static void b(void *arg) {
  pinMode(sw, INPUT_PULLUP);
  while (1){
    while (digitalRead(sw)==LOW) {
      xSemaphoreGive(sem);
      vTaskDelay((200L * configTICK_RATE_HZ) / 1000L);
    }
  }
}
void setup() {
  pinMode(10,OUTPUT);
  digitalWrite(10,LOW);
  portBASE_TYPE s1, s2;
  sem = xSemaphoreCreateCounting(1, 0);
  s1 = xTaskCreate(a, NULL, configMINIMAL_STACK_SIZE, NULL, 2, NULL);
  s2 = xTaskCreate(b, NULL, configMINIMAL_STACK_SIZE, NULL, 2, NULL);
  if (s1 != pdPASS || s2 != pdPASS) {
    pinMode(led, OUTPUT);
    digitalWrite(led, HIGH);
    while (1);
  }
  // put your setup code here, to run once:
  vTaskStartScheduler();
  while (1);
}

void loop() {
  // put your main code here, to run repeatedly:

}
